' Written by Craig'n'Dave
Module Module1
    ' Binary search using an array/list
    Sub binary_search(items() As String, item_to_find As String)
        Dim found As Boolean = False
        Dim first As Integer = 0
        Dim midpoint As Integer = 0
        Dim last As Integer = items.Count - 1
        ' Repeat until the item is found or no items are left to check
        While first <= last And found = False
            ' Calculate the mid point using integer division
            midpoint = (first + last) \ 2
            ' Item found
            If items(midpoint) = item_to_find Then
                found = True
            Else
                ' Recalculate the mid point
                If items(midpoint) < item_to_find Then
                    first = midpoint + 1
                Else
                    last = midpoint - 1
                End If
            End If
        End While
        If found = True Then
            Console.WriteLine("Item found at position " & midpoint)
        Else
            Console.WriteLine("Item not found")
        End If
    End Sub

    Sub Main()
        Dim items() As String = {"Alabama", "California", "Delaware", "Florida", "Georgia"}
        Console.WriteLine("Enter the state to find: ")
        Dim item_to_find As String = Console.ReadLine
        binary_search(items, item_to_find)
    End Sub
End Module
